package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.DeptBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDeptMapper extends BaseMapper<DeptBean> {
    @Select("SELECT d.*,COUNT(e.pk_emId) emNum FROM t_dept d LEFT JOIN t_employee e ON  d.pk_deptId=e.fk_deptId GROUP BY d.pk_deptId")
    @ResultMap("deptMap")
    List<DeptBean> findAll();

    @Delete("delete from t_employee where fk_deptId = #{id};" +
            "delete from t_dept where pk_deptId = #{id};")
    void delCasede(Integer id);

    @Delete("update t_employee set fk_deptId=null where fk_deptId=#{id};" +
            "delete from t_dept where pk_deptId=#{id}")
    void delSetNull(Integer id);
}
